'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview vip等级
 * @author sundbcn@gmail.com (sun debing)
 */

var async = require('async');
var moment = require('moment');
var modelUtil = require('../util/modelUtil');
var constantUtil = require('../util/constantUtil');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var shopSchema = require('../schemas/shopSchema');
var Shop = mongoConnector().model('Shop');
var playerManager = require('../libs/playerManager');

/**
 * 根据role_id获取model
 * @return {[type]} [description]
 */
module.exports.getByRoleId = function (role_id, cb) {
    modelUtil.getByRoleId(Shop, role_id, function (err, shop_model) {
        if (!!err) {
            return cb(err);
        }
        _resetShop(shop_model, role_id);
        cb(null, shop_model);
    });
};

/**
 * 重置商城相关信息
 * @return {[type]} [description]
 */
var _resetShop = function (shop_model, role_id) {
    if (moment(shop_model.getLastRefreshTime()) < moment().startOf('day')) {
        shop_model.refresh();
    }
};
